package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YgPosition;
import com.ruoyi.system.service.IYgPositionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职位Controller
 * 
 * @author ruoyi
 * @date 2022-12-01
 */
@RestController
@RequestMapping("/system/position")
public class YgPositionController extends BaseController
{
    @Autowired
    private IYgPositionService ygPositionService;

    /**
     * 查询职位列表
     */
    @PreAuthorize("@ss.hasPermi('system:position:list')")
    @GetMapping("/list")
    public TableDataInfo list(YgPosition ygPosition)
    {
        startPage();
        List<YgPosition> list = ygPositionService.selectYgPositionList(ygPosition);
        return getDataTable(list);
    }

    /**
     * 导出职位列表
     */
    @PreAuthorize("@ss.hasPermi('system:position:export')")
    @Log(title = "职位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YgPosition ygPosition)
    {
        List<YgPosition> list = ygPositionService.selectYgPositionList(ygPosition);
        ExcelUtil<YgPosition> util = new ExcelUtil<YgPosition>(YgPosition.class);
        util.exportExcel(response, list, "职位数据");
    }

    /**
     * 获取职位详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:position:query')")
    @GetMapping(value = "/{pid}")
    public AjaxResult getInfo(@PathVariable("pid") Long pid)
    {
        return success(ygPositionService.selectYgPositionByPid(pid));
    }

    /**
     * 新增职位
     */
    @PreAuthorize("@ss.hasPermi('system:position:add')")
    @Log(title = "职位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YgPosition ygPosition)
    {
        return toAjax(ygPositionService.insertYgPosition(ygPosition));
    }

    /**
     * 修改职位
     */
    @PreAuthorize("@ss.hasPermi('system:position:edit')")
    @Log(title = "职位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YgPosition ygPosition)
    {
        return toAjax(ygPositionService.updateYgPosition(ygPosition));
    }

    /**
     * 删除职位
     */
    @PreAuthorize("@ss.hasPermi('system:position:remove')")
    @Log(title = "职位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pids}")
    public AjaxResult remove(@PathVariable Long[] pids)
    {
        return toAjax(ygPositionService.deleteYgPositionByPids(pids));
    }
}
